package com.etennis.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.etennis.mapper.ClubMapper;
import com.etennis.pojos.entity.Club;
import com.etennis.security.LoginClubDetails;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Objects;

@Service
public class ClubDetailsServiceImpl implements UserDetailsService {
    @Resource
    private ClubMapper clubMapper;
    @Override
    public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException {
        LambdaQueryWrapper<Club> wrapper=new LambdaQueryWrapper<>();
        wrapper.eq(Club::getAccount,userName);
        //new Member("111","$2a$10$Nt6DOmDT9ATPkfBmgBhnUeW3J.ZOvx9ol.f/v4E6DcN43EiEIdGU6");
       Club club=clubMapper.selectOne(wrapper);
        if(Objects.isNull(club)){
            throw new RuntimeException("error");
        }
        return new LoginClubDetails(club,null);
    }
}